package com.example.a28693.duanshipin.utils;

import com.example.a28693.duanshipin.base.BaseFragment;
import com.example.a28693.duanshipin.fragments.CollectFragment;
import com.example.a28693.duanshipin.fragments.HistoryFragment;
import com.example.a28693.duanshipin.fragments.RecommendFragment;

import java.util.HashMap;
import java.util.Map;
//创建和缓存fragment
public class FragmentCreator {

    public final static int INDEX_RECOMMEND = 0;
    public final static int INDEX_COLLECT = 1;
    public final static int INDEX_HISTORY = 2;

    public final static int PAGE_COUNT = 3;

    private static Map<Integer,BaseFragment> sCache = new HashMap<>();

    public static BaseFragment getFragment(int index){
        BaseFragment baseFragment = sCache.get(index);
        if (baseFragment != null) {
            return baseFragment;
        }
        switch (index){
            case INDEX_RECOMMEND:
                baseFragment = new RecommendFragment();
                break;
            case INDEX_COLLECT:
                baseFragment = new CollectFragment();
                break;
            case INDEX_HISTORY:
                baseFragment = new HistoryFragment();
                break;
        }

        sCache.put(index,baseFragment);
        return baseFragment;
    }

}
